﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MSBDATAModel;


public partial class KHLichSuGiaoDich : System.Web.UI.Page
{
    MSBDATAEntities entities = new MSBDATAEntities();
    TAI_KHOAN_WEB _tk = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["login"] != null)
        {
            if (!IsPostBack)
            {
                string username = Session["login"].ToString();

                var matches = from tk in entities.TAI_KHOAN_WEB
                              where tk.TenDangNhap == username
                              select tk;
                try
                {
                    _tk = matches.First();

                    if (_tk.DuocKichHoat == false)
                    {
                        Response.Redirect("KHDefault.aspx");
                        return;
                    }
                    DropDownList1.DataTextField = "TenLoaiGD";
                    DropDownList1.DataValueField = "MaLoaiGD";
                    DropDownList1.DataSource = entities.C_LOAI_GD_KHACH_HANG;
                    DropDownList1.DataBind();

                }

                catch (Exception)
                {
                    Response.Redirect("NotLogin.aspx");
                }
            }
        }
        else
            Response.Redirect("NotLogin.aspx");
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Session["login"] != null)
        {
            int maLoai = int.Parse(DropDownList1.SelectedValue);
            try
            {
                
                string username = Session["login"].ToString();
                switch (maLoai)
                { 
                    case 1:// Thanh toan truc tuyen
                        this.GridView1.DataSource = from g in entities.GIAO_DICH_KHACH_HANG
                                                    where g.TAI_KHOAN_WEB.TenDangNhap == username
                                                    && g.C_LOAI_GD_KHACH_HANG.MaLoaiGD == maLoai
                                                    select new { 
                                                        ThoiGianThanhToan = g.ThoiGianGD,
                                                        TKChuyen = g.MaTKChuyenTien,
                                                        NHChuyen = g.MaNganHangChuyen,
                                                        TKNhan = g.MaTKNhanTien,
                                                        NHNhan = g.MaNganHangNhan,
                                                        SoTien = g.SoTien,
                                                        MaTenTe = g.MaTienTe,
                                                        TyGia = g.C_TY_GIA.TyGia,
                                                        KetQuaGD = g.C_KET_QUA_GD_KHACH_HANG.TenKetQua
                                                    };
                        break;
                    case 2:// Nap tien
                        this.GridView1.DataSource = from g in entities.GIAO_DICH_KHACH_HANG
                                                    where g.TAI_KHOAN_WEB.TenDangNhap == username
                                                    && g.C_LOAI_GD_KHACH_HANG.MaLoaiGD == maLoai
                                                    select new { 
                                                        ThoiGianNap = g.ThoiGianGD,
                                                        SoTienNap = g.SoTien,
                                                        MaTienTe = g.MaTienTe,
                                                        MaTheDuocNap = g.MaTKGiaoDich,
                                                        DuocDuyet = g.DuocDuyet
                                                    };
                        break;
                    case 3:// Rut tien
                        this.GridView1.DataSource = from g in entities.GIAO_DICH_KHACH_HANG
                                                    where g.TAI_KHOAN_WEB.TenDangNhap == username
                                                    && g.C_LOAI_GD_KHACH_HANG.MaLoaiGD == maLoai
                                                    select new
                                                    {
                                                        ThoiGianRut = g.ThoiGianGD,
                                                        SoTienRut = g.SoTien,
                                                        MaTienTe = g.MaTienTe,
                                                        MaTheDuocRut = g.MaTKGiaoDich                                                        
                                                    };
                        break;
                    case 4: // Chuyen tien qua the ATM
                        break;
                }
                this.GridView1.DataBind();
            }
            catch (Exception)
            {

            }
        }
    }
}